﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BuilderPatternExample
{
    class Program
    {
        static void Main(string[] args)
        {
            var vehicleCreator = new VehicleCreator(new FordExplorerBuilder());
            vehicleCreator.CreateVehicle();
            var vehicle = vehicleCreator.GetVehicle();
            vehicle.ShowInfo();

            Console.WriteLine("---------------------------------------------");
            Console.ReadLine();
        }
    }

    public abstract class VehicleBuilder
    {
        protected Vehicle _Vehicle;

        public Vehicle GetVehicle()
        {
            return _Vehicle;
        }

        public void CreateVehicle()
        {
            _Vehicle = new Vehicle();
        }

        public abstract void SetModel();
        public abstract void SetEngine();
        public abstract void SetTransmission();
    }

    public class Vehicle
    {
        public string Model { get; set; }
        public string Engine { get; set; }
        public string Transmission { get; set; }

        public Vehicle()
        { }

        public void ShowInfo()
        {
            Console.WriteLine("Model: {0}", Model);
            Console.WriteLine("Engine: {0}", Engine);
            Console.WriteLine("Transmission: {0}", Transmission);
        }
    }

    public class VehicleCreator
    {
        private readonly VehicleBuilder _vBuilder;

        public VehicleCreator(VehicleBuilder vb)
        {
            _vBuilder = vb;
        }

        public void CreateVehicle()
        {
            _vBuilder.CreateVehicle();
            _vBuilder.SetModel();
            _vBuilder.SetEngine();
            _vBuilder.SetTransmission();
        }

        public Vehicle GetVehicle()
        {
            return _vBuilder.GetVehicle();
        }
    }

    class FordExplorerBuilder : VehicleBuilder
    {
        public override void SetModel()
        {
            _Vehicle.Model = "Ford Explorer";
        }

        public override void SetEngine()
        {
            _Vehicle.Engine = "4.0 L Cologne V6";
        }

        public override void SetTransmission()
        {
            _Vehicle.Transmission = "5-speed M5OD-R1 manual";
        }
    }
}
